<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="java.math.BigDecimal"%>
<%@page import="inet.db.tennis.TennisSeason"%>
<%@page import="inet.db.tennis.TennisPhase"%>
<%@page import="inet.util.StringTool"%>
<%@page import="inet.db.tennis.TennisMatch"%>
<%@page import="inet.db.tennis.buffer.TennisBuffer"%>
<%@page import="inet.db.tennis.TennisPlayer"%>
<%@page import="inet.db.tennis.TennisMatchGame"%>
<%@page import="inet.db.tennis.TennisSet"%>
<%@page import="inet.db.tennis.TennisGame"%>
<%@page import="inet.db.tennis.TennisGameDetail"%>
<%@page import="inet.db.tennis.TennisEvent"%>
<jsp:useBean id="tennisMatchDAO" class="inet.db.tennis.TennisMatchDAO" scope="session"/>
<jsp:useBean id="tennisGameDAO" class="inet.db.tennis.TennisGameDAO" scope="session"/>
<jsp:useBean id="tennisSetDAO" class="inet.db.tennis.TennisSetDAO" scope="session"/>
<jsp:useBean id="tennisEventDAO" class="inet.db.tennis.TennisEventDAO" scope="session"/>
<table style="width: 100%;">
<%
	String sSetId = request.getParameter("setId");
	BigDecimal setId = BigDecimal.ZERO;
	if(sSetId != null && StringTool.isNumberic(sSetId)) {
		setId = new BigDecimal(sSetId);
	}
	Vector vGameDetail = tennisGameDAO.findDetailSet(setId);
	if(vGameDetail != null && !vGameDetail.isEmpty()) {
		TennisGameDetail detail = null;
		BigDecimal gameId = BigDecimal.ZERO;
		String serve = "<span class=\"tennis-serve\" title=\"Serving player\">&nbsp;&nbsp;</span>";
		String setPoint = "<span class=\"ball-type-text setball\" title=\"Set point\">SP</span>";
    	String matchPoint = "<span class=\"ball-type-text matchball\" title=\"Match point\">MP</span>";
		int i = 1;
		String cls = "";
		int lastScore1 = 0;
		int lastScore2 = 0;
		int lastTieBreakScore1 = 0;
		int lastTieBreakScore2 = 0;
		int countTiebreak = 0;
		for (Iterator it = vGameDetail.iterator(); it.hasNext(); ){
			detail = (TennisGameDetail) it.next();
			if(detail == null ) continue;
			if(i % 2 == 0){
				cls = "log_even";
			} else {
				cls = "log_odd";
			}
			if(detail.getType() == TennisGame.TYPE_TIE_BREAK) {
				countTiebreak += 1;
%>
	<tr class="<%= cls %>">
		<td width="35%" align="right">
			<%
				if (detail.getSpecialPoint() == TennisEvent.SPECIAL_SET_POINT && detail.getScore1() > detail.getScore2()){
					out.println(setPoint);
				}
			%>
		</td>
		<td class="server"><%= detail.getServe() == 1 ? serve:"" %></td>
		<td align="center">
			<span class="<%= detail.getScore1() > lastTieBreakScore1 ? "bold-score":"" %>">
				<%= detail.getScore1() %>
			</span> - 
			<span class="<%= detail.getScore2() > lastTieBreakScore2 ? "bold-score":"" %>">
				<%= detail.getScore2() %>
			</span>
		</td>
		<td class="server"><%= detail.getServe() == 2 ? serve:"" %></td>
		<td width="35%" align="left">
			<%
				if (detail.getSpecialPoint() == TennisEvent.SPECIAL_SET_POINT && detail.getScore2() > detail.getScore1()){
					out.println(setPoint);
				}
			%>
		</td>
	</tr>
<%
				if(countTiebreak == 1) {
					
%>
	<tr>
		<td colspan="5" class="h-part" align="center">Tie-break</td>
	</tr>
<% 				
				} else {
					lastTieBreakScore1 = detail.getScore1();
					lastTieBreakScore2 = detail.getScore2();
				}
			} else {
%>
	<tr class="<%= cls %>">
		<td width="35%"></td>
		<td class="server"><%= detail.getServe() == 1 ? serve:"" %></td>
		<td align="center">
			<span class="<%= detail.getScore1() > lastScore1 ? "bold-score":"" %>">
				<%= detail.getScore1() %>
			</span> - 
			<span class="<%= detail.getScore2() > lastScore2 ? "bold-score":"" %>">
				<%= detail.getScore2() %>
			</span>
		</td>
		<td class="server"><%= detail.getServe() == 1 ? "":serve %></td>
		<td width="35%" align="left"></td>
	</tr>
	<tr class="<%= cls %>">
		<td colspan="5"><%= detail.getListEvent() %></td>
	</tr>
<%
			}
			i++;
			lastScore1 = detail.getScore1();
			lastScore2 = detail.getScore2();
		}
	}
%>
</table>
